home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.netins.net!isac!gg
- From: gg@isac.hces.com (Greg Goodrich)
- Subject: Re: Possible to use #define to define global variable?
- Message-ID: <1996Feb26.212847.29837@isac.hces.com>
- Organization: Health Care Expert Systems
- X-Newsreader: TIN [version 1.2 PL2]
- References: <31311b97.1170723@news.csus.edu>
- Date: Mon, 26 Feb 1996 21:28:47 GMT
-
- Jerry Leong (wleong@sfsu.edu) wrote:
- : Hi,
- : I recently need to do programming that restrict the number of
- : bytes in a structure. Knowing that it might not possible to turn off
- : padding in the structure, I am now thinking if it is possible to use
- : #define to define a global variable? That way, I can fix the size
- : of my structure without worrying about the padding.
-
- : Here's what I have in mind :
-
- : Normally,
- : struct MSG{
- : char buffer[3];
- : };
- : sizeof(struct MSG) is 4 due the the padding on the structure.
-
- : What if,
- : #define buffer char[3];
- : That might work, but than I couldn't assign anything to buffer due
- : to the nature of #define.
-
- : Is there anyway to work around this problem?
-
- : p/s: I am currently working on UNIX for this program. Thanx in advance
-
- : for your responce.
-
- #define's are basically macro substitutions that only exist at compile
- time. The example above will not do you any good, as it will simply
- replace every occurrence of "buffer" with "char[3]" which is not what
- you want. I do not believe there is any way to "force" the compiler to
- allocate a block for you that doesn't fall on a boundary, and as long as
- you don't "hack" in your code, this shouldn't be a problem, as it will
- be basically invisible to you as a programmer. The only thing it will
- do is add a little extra memory usage to the program.
-
- Greg.
- --
- _______________________________________
- Greg Goodrich - gg@hces.com
- Software Engineer
- PACE Health Management Systems
-